{include file="public/nheader"}
<div class="layui-fluid layui-bg-white">
    <!-- <form action="{:url()}" class="layui-form layui-form-fixed"> -->
    <div class="layui-form layui-form-fixed">
        <div class="layui-form-item">
            <label class="layui-form-label">
                套餐名称
            </label>
            <div class="layui-input-block">
                <input type="text" name="title" required="" lay-verify="required" autocomplete="off" class="layui-input"
                    value="{$row.titles|default=''}" placeholder="套餐名称" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                导入产品
            </label>
            <div class="layui-input-block">
                <button class="layui-btn icon-btn layui-btn-warm" id="excels">导入产品(导入格式请根据导出格式)
                </button>
            </div>
        </div>
        <!-- <div class="layui-form-item">
                <label class="layui-form-label">
                    搜索产品
                </label>
                <div class="layui-input-block">
                    <div class="layui-form">
                        <input type="hidden" name="id" required="" lay-verify="required" autocomplete="off"
                            class="layui-input" value="{$row.id|default=''}" placeholder="套餐名称" disabled>
                        <input type="text" name="titles" autocomplete="new-password" class="layui-input"
                            placeholder="产品名称">
                        <button class="layui-btn" lay-filter="submitIframes" type="button" lay-submit>搜索</button>
                    </div>
                </div>
            </div> -->
        <div class="layui-form-item">
            <label class="layui-form-label">
                产品列表
            </label>
            <div class="layui-input-block">
                <table class="layui-table">
                    <colgroup>
                        <col width="200">
                        <col width="150">
                        <col width="100">
                    </colgroup>
                    <thead>
                        <tr>
                            <th>产品名称</th>
                            <th>规格</th>
                            <th>单位</th>
                            <th>单价</th>
                            <th>数量</th>
                            <th>总价</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {if !empty($taocanlog)}
                        {foreach $taocanlog as $tc}
                        <tr>
                            <input name="taocanlogid" type="hidden" value="{$tc.id|default='0'}" />
                            <td>ID:{$tc.productid|default=''}({$tc.title|default=''})</td>
                            <td>{$tc.guige|default=''}</td>
                            <td>{$tc.unit|default=''}</td>
                            <td>{$tc.price|default=''}元</td>
                            <td>{$tc.numbers|default=''}</td>
                            <td>{$tc.price*$tc.numbers}元</td>
                            <td>
                                <a class="layui-btn layui-btn-btn layui-btn-sm"
                                    onclick="taocanedit('{$tc.id}')">修改数量</a>
                                <a class="layui-btn layui-btn-btn layui-btn-sm layui-btn-danger"
                                    onclick="taocan('{$tc.id}')">删除</a>
                            </td>
                        </tr>
                        {/foreach}
                        {/if}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <!-- </form> -->

</div>
{include file="public/nfooter"}
<script>
    function taocanedit(id) {
        layer.prompt({ title: '请填写修改后产品数量', placeholder: '设置修改后产品数量' }, function (value) {
            console.log(value, id); //得到value
            layui.$.post("{:url('agent/taocanlog_del')}", { id: id, numbers: value, status: 1 }, function (res) {
                if (res.code == 200) {
                    layer.msg(res.msg);
                    location.reload();
                } else {
                    layer.error(res.msg);
                }
            }, 'json');
        });
        return false;
    }
    function taocan(id) {
        layer.confirm('确定删除吗?', { icon: 3, title: '提示' }, function () {
            layui.$.post("{:url('agent/taocanlog_del')}", { id: id, status: 0 }, function (res) {
                if (res.code == 200) {
                    layer.msg(res.msg);
                    location.reload();
                } else {
                    layer.error(res.msg);
                }
            }, 'json');
            return false;
        });

    }
    layui.use(['form', 'layer', 'upload'], function () {
        $ = layui.jquery;
        var form = layui.form
            , upload = layui.upload
            , element = layui.element
            , layer = layui.layer;
        // 监听权限提交
        var taocanid = "{$row.id|default=0}";
        form.on("submit(submitIframes)", function (get) {
            console.log(get, taocanid);
            layui.$.get("{:url('agent/taocan_edit')}", get.field, function (res) {
                form.render();
                location.reload();
            }, 'json');

            return false;
        })
        var uploadInst = upload.render({
            elem: '#excels' //绑定元素
            , accept: 'file'
            , url: '/agent/import_taocanlist' //上传接口
            , data: { id: taocanid }
            , before: function (obj) { //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                layer.load(); //上传loading
            }
            , done: function (res) {
                layer.closeAll('loading'); //关闭loading
                //如果上传失败
                if (res.status == 0) {
                    var str = '';
                    $.each(res.data, function (i, obj) {
                        console.log(i, obj);
                        str += '<div>' + obj + '</div>';
                    });
                    layer.open({
                        type: 0,
                        content: str,
                        yes: function () {
                            location.reload();
                        }
                    });
                    return false;
                } else {
                    layer.msg(res.mag, { icon: 2, time: 1000 });
                    return false;
                }
            }
            , error: function () {
                layer.closeAll('loading'); //关闭loading
                layer.msg('请求失败请重试', { icon: 2, time: 1000 });
                return false;

            }
        });
        // 监听权限提交
        form.on("submit(delPage)", function (post) {
            layui.$.post("{:url('agent/taocanlog_del')}", post.field, function (res) {
                if (res.code == 200) {
                    layer.msg(res.msg);
                    // 关闭当前窗口
                    form.render();
                    location.reload();
                } else {
                    layer.error(res.msg);
                }
            }, 'json');
            return false;
        })
        // 监听权限提交
        form.on("submit(submitPage)", function (post) {
            layui.$.post("{:url('agent/taocan_edit')}", post.field, function (res) {
                if (res.code == 200) {
                    layer.msg(res.msg);
                    // 关闭当前窗口
                    form.render();
                    location.reload();
                } else {
                    layer.error(res.msg);
                }
            }, 'json');

            return false;
        })
    });
</script>